#pragma once
#include "pch.h"

namespace fxcc
{
    struct AudioSource
    {
        struct Desc
        {
            std::string m_WavPath;

            std::string m_OggPath;

            enum Type {
                _Wav_ = 0, _Ogg_,
            } m_Type;

            bool operator < (const Desc& other) const
            {
                return std::tie(m_Type, m_WavPath, m_OggPath) < std::tie(other.m_Type, other.m_WavPath, other.m_OggPath);
            }
            std::string GetFilePath() const
            {
                switch (m_Type)
                {
                case Type::_Wav_:
                    return m_WavPath;
                case Type::_Ogg_:
                    return m_OggPath;
                default:
                    return "";
                }
                return "";
            }
        } m_Desc;


        AudioSource(const Desc& desc);

        unsigned int m_Source;

        unsigned int m_Buffer;

        bool m_Available{ 0 };

        bool Init();

        bool InitWav();

        bool InitOgg();

        void Create();

        void BufferData(int format, const short* data, int size, int freq);

        void Play();

        void Pause();

        void Stop();

        void WaitEnd();

        int GetState();

        int GetInt(int param);

        void SetInt(int param, int value);

        float GetFloat(int param);

        void SetFloat(int param, float value);

        float GetGain();

        void SetGain(float gain);

        void SetVec3(int param, float x, float y, float z);

        void GetVec3(int param, float& x, float& y, float& z);

        void SetIVec3(int param, int x, int y, int z);

        void GetIVec3(int param, int& x, int& y, int& z);

        void Delete();

        ~AudioSource();
    };
}
